from jili.calc import calcor_base
import numpy as np
class X1yan3yin(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["X3yan3yin"]
        self.input = ["open","close"]
        self.parameters = {"timeperiod":3}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]+1
        self.n=self.parameters["timeperiod"]
        self.lookback = self.batch - 1
    def calc(self):
        rst=0
        o = self.hisbars[self.input[0]]
        c = self.hisbars[self.input[1]]
        o1=o[self.n]
        c1=c[self.n]
        o2 = o[:self.n]
        c2 = c[:self.n]
        t1=c2>o2
        if False not in t1:#3yan
            if c1<o1:
                t2=c2<o1
                if False not in t2:
                    t3 = o2>c1
                    if False not in t3:
                        rst=-2
        elif True not in t1:#3yin
            if c1 > o1:
                t2 = c2 >o1
                if False not in t2:
                    t3 = o2 < c1
                    if False not in t3:
                        rst = 2
        return rst

